#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const process = require('process');
const rootPath = process.cwd();
require('shelljs/global');
require('colors');
module.exports = function createJson (data, filePath) {
    if (!test('-f', filePath)) {
        echo('创建json文件');
        touch('-r', filePath);
    }
    return new Promise ((resolve, reject) => {
        fs.open(filePath, "w", 0644, function(e, fd) {
            if(e) throw e;
            fs.write(fd, data, 0, 'utf8', function(e){
                if(e) throw e;
                fs.closeSync(fd);
                resolve(data);
            })
         });
    });
}
